import 'package:flutter/material.dart';
import 'package:tender_flutter/constant/app_constant.dart';
import 'package:tender_flutter/constant/resource_path.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/page/home/item/tender_list_cell.dart';
import 'package:tender_flutter/page/home/model/market_entity.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/utils/utils.dart';
import 'package:tender_flutter/widgets/text_highlight.dart';

class MarketListCell extends StatefulWidget {
  const MarketListCell(
      {Key key, this.data, this.onTap, this.onCollection, this.keyword})
      : super(key: key);

  final MarketList data;
  final String keyword;
  final CollectionCallback onCollection;
  final GestureTapCallback onTap;

  @override
  _TenderListCellState createState() => _TenderListCellState();
}

class _TenderListCellState extends State<MarketListCell> {
  @override
  Widget build(BuildContext context) {
    return _initCell();
  }

  Widget _initCell() {
    return GestureDetector(
      onTap: widget.onTap,
      child: Container(
          color: ThemeColors.colorWhite,
          child: Stack(
            children: <Widget>[
              Column(
                children: <Widget>[
                  Container(
                      margin: EdgeInsets.only(
                          right: ScreenAdapter.width(40),
                          top: ScreenAdapter.height(30)),
                      child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            /// TODO 此处typeCode为空应该另行处理
                            Image.asset(
                                RPath.imgPath +
                                    ((widget.data.typeCode ==
                                            AppConstant.MARKET_SUPPLY)
                                        ? "img_supply.png"
                                        : "img_demand.png"),
                                width: ScreenAdapter.width(110),
                                height: ScreenAdapter.height(40)),
                            RichText(
                                text: TextSpan(
                              text: widget.data.num ?? "0",
                              style: TextStyle(
                                fontSize: ScreenAdapter.sp(26),
                                color: ThemeColors.colorType30,
                              ),
                              children: <TextSpan>[
                                TextSpan(
                                    text: ' 人已联系',
                                    style: TextStyle(
                                      fontSize: ScreenAdapter.sp(26),
                                      color: ThemeColors.colorType31,
                                    )),
                              ],
                            ))
                          ])),
                  SizedBox(height: ScreenAdapter.height(25)),
                  Container(
                      margin: EdgeInsets.symmetric(
                          horizontal: ScreenAdapter.width(30)),
                      width: double.infinity,
                      child: TextHighlight(
                        content: widget.data.title ?? "-",
                        keyWords:
                            isEmpty(widget.keyword) ? null : [widget.keyword],
                        maxLines: 2,
                        normalStyle: TextStyle(
                            color: ThemeColors.colorType1,
                            fontSize: ScreenAdapter.sp(32),
                            fontWeight: FontWeight.w500),
                        highlightStyle: TextStyle(
                            color: ThemeColors.colorType56,
                            fontSize: ScreenAdapter.sp(32),
                            fontWeight: FontWeight.w500),
                      )),
                  SizedBox(height: ScreenAdapter.height(30)),
                  Container(
                      margin: EdgeInsets.symmetric(
                          horizontal: ScreenAdapter.width(30)),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Row(
                            children: <Widget>[
                              Container(
                                margin: EdgeInsets.only(
                                    right: ScreenAdapter.width(20)),
                                padding: EdgeInsets.only(
                                    left: ScreenAdapter.width(20),
                                    right: ScreenAdapter.width(20),
                                    top: ScreenAdapter.width(10),
                                    bottom: ScreenAdapter.width(10)),
                                child: Text(widget.data.area ?? "-",
                                    style: TextStyle(
                                        color: ThemeColors.colorType40,
                                        fontSize: ScreenAdapter.sp(24))),
                                decoration: BoxDecoration(
                                    color: ThemeColors.colorType20,
                                    borderRadius: new BorderRadius.circular(3)),
                              ),
                              Container(
                                padding: EdgeInsets.only(
                                    left: ScreenAdapter.width(20),
                                    right: ScreenAdapter.width(20),
                                    top: ScreenAdapter.width(10),
                                    bottom: ScreenAdapter.width(10)),
                                child: Text((widget.data.money ?? "0") + "元",
                                    style: TextStyle(
                                        color: ThemeColors.colorType42,
                                        fontSize: ScreenAdapter.sp(24))),
                                decoration: BoxDecoration(
                                    color: ThemeColors.colorType41,
                                    borderRadius: new BorderRadius.circular(3)),
                              ),
                            ],
                          ),
                          Text(widget.data.createDate ?? "-",
                              style: TextStyle(
                                  color: ThemeColors.colorType1,
                                  fontSize: ScreenAdapter.sp(24))),
                        ],
                      )),
                  SizedBox(height: ScreenAdapter.height(20)),
                ],
              ),
              Offstage(
                  offstage: (widget.data.isTop ? false : true),
                  child: Container(
                      alignment: Alignment.topRight,
                      child: Image.asset(
                        RPath.imgPath + "icon_top.png",
                        width: ScreenAdapter.width(80),
                        height: ScreenAdapter.width(80),
                      )))
            ],
          )),
    );
  }
}
